﻿using IQIGame.Onigao.Framework;
using IQIGame.Onigao.Logic;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay
{
    public static class StoryFactoryClient
    {
        public static StoryActionData CreateActionData(this EStoryAction type)
        {
            switch (type)
            {
                case EStoryAction.Move:
                    return new StoryActionData_Move();
                case EStoryAction.Fade:
                    return new StoryActionData_Fade();
                case EStoryAction.Shake:
                    return new StoryActionData_Shake();
                case EStoryAction.Scale:
                    return new StoryActionData_Scale();
                case EStoryAction.Animation:
                    return new StoryActionData_Animation();
                case EStoryAction.Queue:
                    return new StoryActionData_Queue();
                case EStoryAction.Parallel:
                    return new StoryActionData_Parallel();
            }
            return new StoryActionData();
        }

        public static StoryAction GetAction(UIStory ui, GameObject root, StoryActionData config)
        {
            StoryAction action = null;
            switch (config)
            {
                case StoryActionData_Move:
                    action = ClassPool<StoryAction_Move>.Get();
                    break;
                case StoryActionData_Fade:
                    action = ClassPool<StoryAction_Fade>.Get();
                    break;
                case StoryActionData_Shake:
                    action = ClassPool<StoryAction_Shake>.Get();
                    break;
                case StoryActionData_Scale:
                    action = ClassPool<StoryAction_Scale>.Get();
                    break;
                case StoryActionData_Animation:
                    action = ClassPool<StoryAction_Animation>.Get();
                    break;
                case StoryActionData_Queue:
                    action = ClassPool<StoryAction_Queue>.Get();
                    break;
                case StoryActionData_Parallel:
                    action = ClassPool<StoryAction_Parallel>.Get();
                    break;
            }
            if (action != null)
            {
                if (action.Initialize(ui, root, config))
                {
                    return action;
                }
                action.Free();
            }
            return null;
        }
    }
}